package com.vinfai.patterns.proxy;
/**
 * 1、实现共同的接口、抽象类。
 * 2、代理对象中保护真实对象的引用
 * @author vinfai
 *
 */
public class ProxySubject extends AbstractSubject {
	
	//*****真实对象的引用
	public AbstractSubject realSubject;
	
	@Override
	public void doRequest() {
		preRequest();
		getRealSubject().doRequest();
		postRequest();
	}
	
	public AbstractSubject getRealSubject(){
		if(realSubject==null){
			realSubject = new RealSubject();
		}
		return realSubject;
	}
	
	private void preRequest(){
		logger.info("before real subject invoked.");
	}
	
	private void postRequest(){
		logger.info("after realSubject invoked.");
	}
}
